
# 1.复制网卡文件/etc/sysconfig/network-scripts/ifcfg-ens33 到家目录，并且改名为wangka.txt
# cp /etc/sysconfig/network-scripts/ifcfg-ens33 /root/wangka.txt
# 2.找到含有 IP 的行输出
# cat /root/wangka.txt | grep "IP"
# 3.显示文件的第 3 行到第 5 行的内容
# sed -n '3,5 p' /root/wangka.txt
# 4.将文件中的255全部替换为250
# sed 's/255/250/g' /root/wangka.txt
# 5.以文件IPADDR开头的上一行添加hello
# sed '/^IPADDR/i hello' /root/wangka.txt
# 6.找到所有DNS，并且删掉
# sed 's/DNS//g' /root/wangka.txt
# 7.使用管道符连续处理4. 5. 6. 题，并且重定向结果保存为wang
# sed 's/255/250/g' /root/wangka.txt | sed '/^IPADDR/i hello' |
# sed 's/DNS//g' > /root/wang.txt
# 8. 根据wangka.csv文件自己灵活处理重定向为ip.txt,内容如下：
# 192.168.145.151
# 250.250.250.0
# 192.168.145.2
# 8.8.8.8
# 114.114.114.114
# sed -i '1,$d' /root/wangka.txt
# printf "192.168.145.151
# 250.250.250.0
# 192.168.145.2
# 8.8.8.8
# 114.114.114.114\n" /root/wangka.txt > /root/ip.txt
# cat /root/wangka.txt
# 9. ip.txt中以.分割，按照第一列进行降序排序
# sort -t "." -nrk 1 /root/ip.txt
# 10. ip.txt中以.为分隔符，打印第1列和第2列
# awk -v FS="." '{print $1,$2}' /root/ip.txt
# 11. ip.txt中以.为分隔符，打印第3列和第4列，列之间用,分割
# awk -v FS="." -v OFS="," '{print $3,$4}' /root/ip.txt
# 12. ip.txt中以.为分隔符，列之间用,分割，且加一行，保存为ip.csv,格式如下：
# one,two,three,four
# 192,168,145,151
# 250,250,250,0
# 192,168,145,2
# 8,8,8,8
# 114,114,114,114
# sed -i '1i one,two,three,four' /root/ip.txt #直接修改ip.txt
# sed 's/one.two,three,four//g' /root/ip.txt 
# sed '/^192.168.145.151/i one,two,three,four' /root/ip.txt > /root/ip.csv #将输出结果导出成ip.csv
# 13. 在家目录下创建一个names.txt的文件，写入班级的所有同学的姓名，每个一行，每
# 次随机产生一个姓名
# touch /root/names.txt
# printf "aaa\nbbb\nccc\nxxx\nyyy\nzzz\njjj\nkkk\nlll\n" >> /root/names.txt
# shuf -n 1 /root/names.txt #随机输出一行
# 14.批量修改家目录下的文件扩展名，使用位置参数传递两种扩展名，例如txt文件为csv
# 文件。（注：碰到特殊符号使用\进行转义）
# function changeexts(){
#     folder=$1
# for file in  $folder/*
#     do
#         if [ -f "$file" ] && [[ "$file" == *.txt ]]
#         then
#             mv $file  ${file%.txt}.csv
#         elif [ -d "$file" ]
#         then
#             changeexts $file
#         fi..
#     done
# }
# read -p "请输入一个路径:" lujing
# changeexts $lujing


# printf "bb:40:5.4 
# bd:20:4.2
# xz:50:2.3 
# cls:10:3.5 
# ss:30:1.6\n" > /root/shell/sort.txt

# sed -i d /root/shell/sort.txt 

# sort -t ":" -nrk 3 /root/shell/sort.txt

# sed -n '2 p' /root/shell/sort.txt

# sed -n '2,4 p' /root/shell/sort.txt

# sed 's/bb/BB/g' /root/shell/sort.txt

# sed '/^bb/i hello' /root/shell/sort.txt |
# sed 's/d//g' |
# sed '1i one,two,three,four' > /root/shell/ceshi.txt

#sed  '1i one,two,three,four' /root/shell/sort.txt

#sed  '1d' /root/shell/sort.txt

# awk -v FS=":" '{print $1,$2}' /root/shell/sort.txt

# awk -v FS=":" -v OFS="," '{print$1,$2}' /root/shell/sort.txt

# awk -v FS=":" -v OFS="," 'BEGIN{print "one,two,three"}{print $2,$1,$3}' /root/shell/sort.txt > /root/shell/sort.csv

# awk -v FS=":" '{ if($2>30){print $2}}' /root/shell/sort.txt



# he=0
# function getSum(){
#     num1=$1
# for i in `seq 1 $num1`
#     do
#         he=$(($he+$i))
#         echo "每次$i相加后得到:$he" 
#     done
#     echo "$he"
# }
# read -p "请输入一个数字用于计算他的阶和:" num
# getSum $num


# 掐头-去尾-换行
# sed 's/{"subjects":\[{//g' /root/shell/douban.txt \  #将每单独一串数据中的subjects":\[{去掉，其中\为转义的意思，因为linux中不一定识别[ 
# | sed 's/}\]}//g' \  # 将每单独一串数据中的}\]}去掉，其中\是转义的意思，因为linux中不一定识别[
# | sed 's/},{/\n/g' \  # 以},{为换行基准，将每一个数据对应的一串句子进行换行
# | sed 's/\\//g' \  # 将每一串数据中网址一列中的\删除掉，第一个\表示转义，第二个\表示网址这一列数据中多余的\
# | sed 's/""/null/g' \  # 将数据中多余的""去掉
# | sed 's/"//g' \  # 将数据中多余的"去掉
# | awk -v FS="," -v OFS="," '{print $8,$4,$1,$2,$3,$5,$6,$7,$9,$10}' \  #以，作为分隔符隔离出每一列，以分隔出来的第八列作为表格中的第一列，列与列之间用，分隔 
# | sed 's/id://g' \  #  将每一串数据中的id:删除掉
# | sed 's/title://g' \  # 将每一串数据中的title:删除掉
# | sed 's/episodes_info://g' \  # 将每一串数据中的episodes_info:删除掉
# | sed 's/rate://g' \  # 将每一串数据中的rat:删除掉
# | sed 's/cover_x://g' \  # 将每一串数据中的cover_x:删除掉
# | sed 's/url://g' \  # 将每一串数据中的url:删除掉
# | sed 's/playable://g' \  # 将每一串数据中的playable:删除掉
# | sed 's/cover://g' \  # 将每一串数据中的cover:删除掉
# | sed 's/cover_y://g' \  # 将每一串数据中的cover_y:删除掉
# | sed 's/is_new://g' \  # 将每一串数据中的is_new:删除掉
# | awk -v FS="," -v OFS="," 'BEGIN{print "id,title,episodes_info,rate,cover_x,url,playable,cover,cover_y,is_new"} \  
# {print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10}' > /root/shell/douban111.csv  # BEGIN在表格的第一行插入列名，因为上面的awk语句已经定义好了哪一列作为第一列，所以直接按照顺序打印1-10列即可

#  sed 's/\[{//g' /root/shell/infotest.txt \
#  | sed 's/}\]//g' \
#  | sed 's/"//g' \
#  | awk -v FS="," -v OFS="," '{print $1,$2,$4,$6,$7,$3,$5,$8}' \
#  | sed 's/catchTime://g' \
#  | sed 's/commentCount://g' \
#  | sed 's/createTime://g' \
#  | sed 's/praiseCount://g' \
#  | sed 's/reportCount://g' \
#  | sed 's/content://g' \
#  | sed 's/pic_list://g' \
#  | sed 's/source://g' \
#  | awk -v FS="," -v OFS="," 'BEGIN{print "catchTime,commentCount,createTime,praiseCount,reportCount,content,pic_list,source"} \
#  {print $1,$2,$3,$4,$5,$6,$7,$8}' > /root/shell/infotest.csv
#  | sed 's/catchTime://g' \ 
#  | sed 's/commentCount://g' \
#  | sed 's/createTime://g' \
#  | sed 's/praiseCount://g' \
#  | sed 's/reportCount://g' \
#  | sed 's/content://g' \
#  | sed 's/pic_list://g' \
#  | sed 's/source://g' \
 

#  host="127.0.0.1"
#  port=3306
#  user="root"
#  passwd="root123456"
#  dbname="test"

# # 建表前先删表
#  sql1="drop table if exists $1" 
# mysql -h$host -P$port -u$user -p$passwd $dbname -e "$sql1"

# # 确定没有同名的表后建表
# # 首先获取第一行
# names=`head -n +1 /root/shell/douban.csv | sed 's/,/ /g'`
# # 找出最后一个列名
# lastname=`echo "$names" | awk '{print $NF}'`
# sql2="create table if not exists $1("
#     for i in $names
#     do
#         if [ $i == "$lastname" ]
#         then
#             sql2="$sql2$i varchar(200))"
#         else
#             sql2="$sql2$i varchar(200),"
#         fi
#     done

# mysql -h$host -P$port -u$user -p$passwd $dbname -e "$sql2"

# # 导入数据
# sql3="LOAD DATA INFILE '$2' INTO TABLE $1
# CHARACTER SET utf8
# FIELDS TERMINATED BY ','
# LINES TERMINATED BY '\n'
# IGNORE 1 LINES"
# mysql -h$host -P$port -u$user -p$passwd $dbname -e "$sql3"

# # 查看表和数据
# sql4="select * from $1"
# mysql -h$host -P$port -u$user -p$passwd $dbname -e "$sql4"







